import { rawRequestClient } from '#/api/request';

// 渠道配置接口类型定义
export interface ChannelConfig {
  id?: number;
  channel_id?: number;
  key: string;
  value: string;
  type: string;
  model_name: string;
  tier: number;
  is_enabled: boolean;
  created_at?: string;
  created_by?: string;
}

// 渠道接口类型定义
export interface Channel {
  id?: number;
  name: string;
  type: string;
  base_url: string;
  configs?: ChannelConfig[];
  accounts?: any[];
  created_at?: string;
  created_by?: string;
  updated_at?: string;
  updated_by?: string;
}

// 获取渠道列表
export function getChannelList(params?: {
  page?: number;
  size?: number;
  name?: string;
  type?: string;
}) {
  return rawRequestClient.get(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels`, { params });
}

// 创建渠道
export function createChannel(data: Omit<Channel, 'id' | 'created_at' | 'created_by' | 'updated_at' | 'updated_by' | 'accounts'>) {
  return rawRequestClient.post(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels`, data);
}

// 获取渠道详情
export function getChannelDetail(id: number) {
  return rawRequestClient.get(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels/${id}`);
}

// 更新渠道
export function updateChannel(id: number, data: Omit<Channel, 'id' | 'created_at' | 'created_by' | 'updated_at' | 'updated_by' | 'accounts'>) {
  return rawRequestClient.put(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels/${id}`, data);
}

// 删除渠道
export function deleteChannel(id: number) {
  return rawRequestClient.delete(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels/${id}`);
}

// 添加渠道配置
export function addChannelConfigs(id: number, configs: Omit<ChannelConfig, 'id' | 'created_at' | 'created_by'>[]) {
  return rawRequestClient.post(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels/${id}/configs`, configs);
}

// 删除渠道配置
export function deleteChannelConfigs(ids: number[]) {
  return rawRequestClient.delete(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/channels/configs`, { params: { ids } });
}
